import request from '@/utils/request'
import { ADMIN } from '@/config/baseUrl'

// 查询角色列表
export function listRole(query) {
  return request({
    url: ADMIN + '/system/role/list',
    method: 'get',
    params: query
  })
}

// 查询角色详细
export function getRole(rolecode) {
  return request({
    url: ADMIN + '/system/role/getRole' ,
    method: 'get',
    params: {rolecode : rolecode}
  })
}

// 新增角色
export function addRole(data) {
  return request({
    url: ADMIN + '/system/role',
    method: 'post',
    data: data
  })
}

// 修改角色
export function updateRole(data) {
  return request({
    url: ADMIN + '/system/role',
    method: 'put',
    data: data
  })
}

// 角色数据权限
export function dataScope(data) {
  return request({
    url: ADMIN + '/system/role/dataScope',
    method: 'put',
    data: data
  })
}

// 新增角色人员
export function addUserRole(rolecode,userIds) {
  return request({
    url: ADMIN + '/system/role/addUserRole',
    method: 'post',
    params: {rolecode:rolecode,userIds:userIds}
  })
}

// 角色状态修改
export function changeRoleStatus(roleId, status) {
  const data = {
    roleId,
    status
  }
  return request({
    url: ADMIN + '/system/role/changeStatus',
    method: 'put',
    data: data
  })
}

// 删除角色
export function delRole(rolecodes) {
  return request({
    url: ADMIN + '/system/role/' + rolecodes,
    method: 'delete'
  })
}

// 从角色删除人员
export function delUserRole(rolecode,usernames) {
  return request({
    url: ADMIN + '/system/role/delUserRole',
    method: 'delete',
    params: {rolecode:rolecode,usernames:usernames}
  })
}

// 导出角色
export function exportRole(query) {
  return request({
    url: ADMIN + '/system/role/export',
    method: 'get',
    params: query
  })
}

// 根据用户名查询角色树结构
export function roleTreeselect(username) {
  return request({
    url: ADMIN + '/system/role/roleTreeselect',
    method: 'get',
    params:{username:username}
  })
}


